package com.hrzyit.base.presenter

import android.content.Context
import com.hrzyit.base.presenter.view.BaseView
import com.hrzyit.base.utils.NetWorkUtils
import com.trello.rxlifecycle2.LifecycleProvider
import javax.inject.Inject

/**
 * MVP中P层，所有子 Presenter 均继承此类
 * @author YangWei
 * @date 2019/3/21
 */
open class BasePresenter<T:BaseView> {

    lateinit var mView: T

    // Dagger 注入，上下文
    @Inject
    lateinit var context:Context

    //Dagger注入，Rx生命周期管理
    @Inject
    lateinit var lifecycleProvider: LifecycleProvider<*>

    /**
     * 检查当前网络情况
     */
    fun checkNetWork():Boolean {

        if(NetWorkUtils.isNetWorkAvailable(context)){
            return true
        }
        mView.onError("网络不可用")
        return false
    }
}